#include "SearchEngine.h"

int CurPosition[10][9];
CHESSMOVE m_cmBestMove;
int m_nSearchDepth;
int m_nMaxDepth;
bool is_rule = false;
int moves[4];

int MakeMove(CHESSMOVE* move)
{
	int nChessID;
	nChessID = CurPosition[move->To.y][move->To.x];
	CurPosition[move->To.y][move->To.x] = CurPosition[move->From.y][move->From.x];
	CurPosition[move->From.y][move->From.x] = NOCHESS;
	return nChessID;
}

void UnMakeMove(CHESSMOVE* move,int nChessID)
{
	CurPosition[move->From.y][move->From.x] = CurPosition[move->To.y][move->To.x];
	CurPosition[move->To.y][move->To.x] = nChessID;
}


int IsGameOver(int position[10][9], int nDepth)
{
	int i,j;
	bool RedLive = false, BlackLive=false; 

	for (i = 7; i < 10; i++)
		for (j = 3; j < 6; j++)
		{
			if (position[i][j] == B_KING)
				BlackLive = true;
			if (position[i][j] == R_KING)
				RedLive  = true;
		}

		for (i = 0; i < 3; i++)
			for (j = 3; j < 6; j++)
			{
				if (position[i][j] == B_KING)
					BlackLive = true;
				if (position[i][j] == R_KING)
					RedLive  = true;
			}

			i = (m_nMaxDepth - nDepth + 1) % 2;

			if (!RedLive)
				if (i)
					return 19990 + nDepth;
				else
					return -19990 - nDepth;
			if (!BlackLive)
				if (i)
					return -19990 - nDepth;
				else
					return 19990 + nDepth;
			return 0;
}

void SetSearchDepth(int nDepth)
{
	m_nSearchDepth = nDepth;
};